home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_056 / mcad / mp / source / physio.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  12KB  |  364 lines

  1. #include "struct.h"
  2. #include "plot.h"
  3.  
  4. struct Window *OpenWindow();
  5. struct InputEvent *Intuition();
  6. struct Screen *OpenScreen();
  7. int WrtPlt();
  8.  
  9. struct RastPort *rp;
  10. struct ViewPort *vp;
  11. struct Window *window;
  12. struct IntuiMessage *msg;
  13. struct Screen *screen;
  14.  
  15. struct NewScreen newscreen = {
  16.     0,0,            /* start pos.*/
  17.     MAXHORIZ,MAXVERT,4,    /* width height depth (4 bit planes) */
  18.     0,1,            /* detail pen, block pen */
  19.     HIRES | LACE,         /* viewing mode (640x400 interlaced) */
  20.     CUSTOMSCREEN,        /* screen type */
  21.     NULL,            /* font */
  22.     "mp",            /* screen title */
  23.     NULL            /* gadget pointer */
  24.     };
  25.  
  26. struct NewWindow newwindow = {
  27.     0,0,                    /* Starting corner */
  28.     MAXHORIZ,MAXVERT,            /* Width, height */
  29.     1,14,                    /* detail, block pens */
  30.     MENUPICK | MOUSEMOVE | MOUSEBUTTONS,    /* IDCMP flags */
  31.     ACTIVATE | BORDERLESS | NOCAREREFRESH | REPORTMOUSE,
  32.     NULL,                    /* Pointer to first gadget */
  33.     NULL,                    /* Pointer to checkmark */
  34.     NULL,                    /* title */
  35.     NULL,                    /* screen pointer */
  36.     NULL,                    /* bitmap pointer */
  37.     0,0,0,0,                /* sizing limits */
  38.     CUSTOMSCREEN                /* type of screen */
  39.     };
  40.  
  41.  
  42. void InitColors()
  43. {
  44.    SetRGB4(vp,0,15,10,5);   SetRGB4(vp,1,0,0,0);    SetRGB4(vp,2,15,15,15);
  45.    SetRGB4(vp,3,15,0,0);    SetRGB4(vp,4,0,0,0);    SetRGB4(vp,5,15,0,0);
  46.    SetRGB4(vp,6,0,12,0);    SetRGB4(vp,7,0,5,15);   SetRGB4(vp,8,13,13,0);
  47.    SetRGB4(vp,9,0,13,13);   SetRGB4(vp,10,15,0,15); SetRGB4(vp,11,10,10,0);
  48.    SetRGB4(vp,12,8,8,8);    SetRGB4(vp,13,5,5,0);   SetRGB4(vp,14,0,10,15);
  49.    SetRGB4(vp,15,15,8,0);
  50. }
  51.  
  52. /********/
  53. InitWind()
  54. {
  55.    screen = OpenScreen(&newscreen);
  56.    newwindow.Screen = screen; window = OpenWindow(&newwindow);
  57.    rp = window->RPort; vp = &window->WScreen->ViewPort;
  58.    SetDrMd(rp,JAM1); SetAPen(rp,1);
  59.    InitColors(); return(1);
  60. }
  61.  
  62.  
  63. /*** MENUS **********************************************************/
  64. #define MICFlags (ITEMENABLED | ITEMTEXT | HIGHCOMP | COMMSEQ)
  65. #define MIFlags (ITEMENABLED | ITEMTEXT | HIGHCOMP)
  66.  
  67. /*** MENU 1 ***/
  68. struct IntuiText M_text19 = {1,14,JAM2,0,0,NULL,"XYRegionLock ",NULL};
  69. struct MenuItem    M_item19 = {
  70.    NULL, 0, 9*CHARHEIGHT, CHARWIDTH*14 + COMMWIDTH, CHARHEIGHT, MIFlags,
  71.    0L, (APTR)&M_text19, NULL, NULL, NULL, 0};
  72. #define MI_XYREGIONLOCK 9
  73.  
  74. struct IntuiText M_text18OFF = {1,14,JAM2,0,0,NULL,"YRegionLock ",NULL};
  75. struct IntuiText M_text18ON = {1,14,JAM2,0,0,NULL,"YRegionLOCK ",NULL};
  76. struct MenuItem    M_item18 = {
  77.    &M_item19, 0, 8*CHARHEIGHT, CHARWIDTH*14 + COMMWIDTH, CHARHEIGHT, MIFlags,
  78.    0L, (APTR)&M_text18OFF, NULL, NULL, NULL, 0};
  79. #define MI_YREGIONLOCK 8
  80.  
  81. struct IntuiText M_text17OFF = {1,14,JAM2,0,0,NULL,"XRegionLock ",NULL};
  82. struct IntuiText M_text17ON = {1,14,JAM2,0,0,NULL,"XRegionLOCK ",NULL};
  83. struct MenuItem    M_item17 = {
  84.    &M_item18, 0, 7*CHARHEIGHT, CHARWIDTH*14 + COMMWIDTH, CHARHEIGHT, MIFlags,
  85.    0L, (APTR)&M_text17OFF, NULL, NULL, NULL, 0};
  86. #define MI_XREGIONLOCK 7
  87.  
  88. struct IntuiText M_text16 = {1,14,JAM2,0,0,NULL,"White BG     ",NULL};
  89. struct MenuItem    M_item16 = {
  90.    &M_item17, 0, 6*CHARHEIGHT, CHARWIDTH*14 + COMMWIDTH, CHARHEIGHT, MICFlags,
  91.    0L, (APTR)&M_text16, NULL, 'l', NULL, 0};
  92. #define MI_WHITEBG 6
  93.  
  94. struct IntuiText M_text15 = {1,14,JAM2,0,0,NULL,"Axes         ",NULL};
  95. struct MenuItem    M_item15 = {
  96.    &M_item16, 0, 5*CHARHEIGHT, CHARWIDTH*14 + COMMWIDTH, CHARHEIGHT, MICFlags,
  97.    0L, (APTR)&M_text15, NULL, 'a', NULL, 0};
  98. #define MI_AXES 5
  99.  
  100. struct IntuiText M_text14 = {1,14,JAM2,0,0,NULL,"Grid         ",NULL};
  101. struct MenuItem    M_item14 = {
  102.    &M_item15, 0, 4*CHARHEIGHT, CHARWIDTH*14 + COMMWIDTH, CHARHEIGHT, MICFlags,
  103.    0L, (APTR)&M_text14, NULL, 'g', NULL, 0};
  104. #define MI_GRID 4
  105.  
  106. struct IntuiText M_text13 = {1,14,JAM2,0,0,NULL,"NewData      ",NULL};
  107. struct MenuItem    M_item13 = {
  108.    &M_item14, 0, 3*CHARHEIGHT, CHARWIDTH*14 + COMMWIDTH, CHARHEIGHT, MICFlags,
  109.    0L, (APTR)&M_text13, NULL, 'n', NULL, 0};
  110. #define MI_NEWDATA 3
  111.  
  112. struct IntuiText M_text12 = {1,14,JAM2,0,0,NULL,"FullPlot     ",NULL};
  113. struct MenuItem    M_item12 = {
  114.    &M_item13, 0, 2*CHARHEIGHT, CHARWIDTH*14 + COMMWIDTH, CHARHEIGHT, MICFlags,
  115.    0L, (APTR)&M_text12, NULL, 'f', NULL, 0};
  116. #define MI_FULLPLOT 2
  117.  
  118. struct IntuiText M_text11 = {1,14,JAM2,0,0,NULL,"Zoom         ",NULL};
  119. struct MenuItem    M_item11 = {
  120.    &M_item12, 0, CHARHEIGHT, CHARWIDTH*14 + COMMWIDTH, CHARHEIGHT, MICFlags,
  121.    0L, (APTR)&M_text11, NULL, 'z', NULL, 0};
  122. #define MI_ZOOM 1
  123.  
  124. struct IntuiText M_text10 = {1,14,JAM2,0,0,NULL,"CrossHair     ",NULL};
  125. struct MenuItem    M_item10 = {
  126.    &M_item11, 0, 0, CHARWIDTH*14 + COMMWIDTH, CHARHEIGHT, MICFlags,
  127.    0L, (APTR)&M_text10, NULL, 'h', NULL, 0};
  128. #define MI_XHAIR 0
  129.  
  130. struct Menu Menu1 = {
  131.    NULL, CHARWIDTH*12 + COMMWIDTH, 0, CHARWIDTH*14, CHARHEIGHT, MENUENABLED,
  132.    "Options     ", &M_item10};
  133. #define M_OPTIONS 1
  134.  
  135. /*** MENU 0 ***/
  136. struct IntuiText M_text03 = {1,14,JAM2,0,0,NULL,"Quit        ",NULL};
  137. struct MenuItem    M_item03 = {
  138.    NULL, 0, 3*CHARHEIGHT, CHARWIDTH*12 + COMMWIDTH, CHARHEIGHT, MICFlags,
  139.    0L, (APTR)&M_text03, NULL, 'q', NULL, 0};
  140. #define MI_QUIT 3
  141.  
  142. struct IntuiText M_text02 = {1,14,JAM2,0,0,NULL,"Mk mCADFile ",NULL};
  143. struct MenuItem    M_item02 = {
  144.    &M_item03, 0, 2*CHARHEIGHT, CHARWIDTH*12 + COMMWIDTH, CHARHEIGHT, MIFlags,
  145.    0L, (APTR)&M_text02, NULL, NULL, NULL, 0};
  146. #define MI_MKMCADFILE 2
  147.  
  148. struct IntuiText M_text01 = {1,14,JAM2,0,0,NULL,"Mk PlotFile ",NULL};
  149. struct MenuItem    M_item01 = {
  150.    &M_item02, 0, CHARHEIGHT, CHARWIDTH*12 + COMMWIDTH, CHARHEIGHT, MIFlags,
  151.    0L, (APTR)&M_text01, NULL, NULL, NULL, 0};
  152. #define MI_MKPLOTFILE 1
  153.  
  154. struct IntuiText M_text00 = {1,14,JAM2,0,0,NULL,"Replot      ",NULL};
  155. struct MenuItem    M_item00 = {
  156.    &M_item01, 0, 0, CHARWIDTH*12 + COMMWIDTH, CHARHEIGHT, MICFlags,
  157.    0L, (APTR)&M_text00, NULL, 'r', NULL, 0};
  158. #define MI_REPLOT 0
  159.  
  160. struct Menu Menu0 = {
  161.    &Menu1, 0, 0, CHARWIDTH*12+COMMWIDTH, CHARHEIGHT, MENUENABLED,
  162.    "  Project   ", &M_item00};
  163. #define M_PROJECT 0
  164. /***************************************************************************/
  165.  
  166. /*************/
  167. void InitMenu()
  168. {SetMenuStrip(window,&Menu0); ShowTitle(screen,FALSE);}
  169.  
  170.  
  171. /************/
  172. void CleanUp()
  173. {ClearMenuStrip(window); CloseWindow(window); CloseScreen(screen);}
  174.  
  175.  
  176. /************************/
  177. void AttrOnOff(Pict, item)
  178. struct Pict *Pict;
  179. int item;
  180. {
  181.    ClearMenuStrip(window);
  182.    switch(item) {
  183.    case MI_XREGIONLOCK:
  184.       M_item17.ItemFill = (APTR)(Pict->XRegionLock ? &M_text17ON : &M_text17OFF);
  185.       break;
  186.    case MI_YREGIONLOCK:
  187.       M_item18.ItemFill = (APTR)(Pict->YRegionLock ? &M_text18ON : &M_text18OFF);
  188.       break;
  189.    default: break;
  190.    }
  191.    SetMenuStrip(window, &Menu0);
  192. }
  193.  
  194.  
  195. /**************************************************************************/
  196. void PToU();
  197.  
  198. USHORT InvisPtr[] = {
  199.    0x0,0x0, 0x0,0x0, 0x0,0x0, 0x0,0x0, 0x0,0x0, 0x0,0x0, 0x0,0x0,
  200.    0x0,0x0, 0x0,0x0, 0x0,0x0, 0x0,0x0};
  201.  
  202. static short XHair = FALSE;
  203. static short WhiteBG = FALSE;
  204.  
  205. /*****************/
  206. void PutXHair(x,y)
  207. short x,y;
  208. {Move(rp,0,y); Draw(rp,MAXHORIZ,y); Move(rp,x,0); Draw(rp,x,MAXVERT);}
  209.  
  210. /**************************/
  211. void GetXHair(x,y)
  212. short *x, *y;
  213. {SetPointer(window,InvisPtr,9,9,0,0); SetDrMd(rp,COMPLEMENT); PutXHair(*x,*y);}
  214.  
  215. /***********************/
  216. void KillXHair(x,y)
  217. short x,y;
  218. {ClearPointer(window); PutXHair(x,y); SetDrMd(rp,JAM1);}
  219.  
  220. /*****************************/
  221. void RubberBox(x1, y1, x2, y2)
  222. short *x1, *y1, *x2, *y2;
  223. {
  224.    Move(rp,x1,y1);
  225.    if (XHair) {Draw(rp,x1,y2); Move(rp,x1,y1); Draw(rp,x2,y1);}
  226.    else {Draw(rp,x1,y2); Draw(rp,x2,y2); Draw(rp,x2,y1); Draw(rp,x1,y1);}
  227. }
  228.  
  229. #define NO_OBJECT 0
  230. #define REGION 1
  231. #define LINE 2
  232. #define BOX 3
  233.  
  234. /*************/
  235. CheckUser(Pict)
  236. struct Pict *Pict;
  237. {
  238.    ULONG class;
  239.    USHORT code;
  240.    int retval = NOACTION, MouseMoved;
  241.    short x, y, x0, y0, x1, y1;
  242.    short RubberObj = NO_OBJECT, RubberBand = FALSE;
  243.    FFP XMin, YMin, XMax, YMax;
  244.    struct PlotRegion *Reg;
  245.  
  246.    InitMenu();
  247.    AttrOnOff(Pict, MI_XREGIONLOCK);
  248.    AttrOnOff(Pict, MI_YREGIONLOCK);
  249.    x = y = 0;
  250.    if (XHair) {GetXHair(&x,&y); x1 = x; y1 = y;}
  251.    if (WhiteBG) SetRGB4(vp,0,15,15,15);
  252.    do {
  253.       Wait(1 << window->UserPort->mp_SigBit);
  254.  
  255.       while (msg = (struct IntuiMessage *) GetMsg(window->UserPort) ) {
  256.          class = msg->Class;
  257.          MouseMoved = (class == MOUSEMOVE);
  258.          code = msg->Code; x = msg->MouseX; y = msg->MouseY;
  259.          ReplyMsg(msg);
  260.  
  261.          if ((class == MENUPICK) && (code != MENUNULL)) {
  262.             switch (MENUNUM(code)) {
  263.             case M_PROJECT:
  264.                switch(ITEMNUM(code)) {
  265.                case MI_REPLOT:      retval = REPLOT; break;
  266.                case MI_QUIT:        retval = QUIT; break;
  267.                case MI_MKPLOTFILE:  WrtPlt(Pict); break;
  268.                case MI_MKMCADFILE:  To_mCAD(Pict); break;
  269.                default: break;
  270.                }
  271.                break;
  272.             case M_OPTIONS:
  273.                switch (ITEMNUM(code)) {
  274.                case MI_XHAIR:
  275.                   if (XHair = !XHair) {GetXHair(&x,&y); x1=x; y1=y;}
  276.                   else KillXHair(x1,y1);
  277.                   break;
  278.                case MI_ZOOM:        RubberObj = REGION; break;
  279.                case MI_NEWDATA:     retval = GETHOWTO; break;
  280.                case MI_FULLPLOT:    retval = GETDATALIMITS; break;
  281.                case MI_GRID:        Pict->Grid = !Pict->Grid; break;
  282.                case MI_AXES:        Pict->Axes = !Pict->Axes; break;
  283.                case MI_WHITEBG:
  284.                   if (WhiteBG = !WhiteBG) SetRGB4(vp,0,15,15,15);
  285.                   else SetRGB4(vp,0,15,10,5);
  286.                   break;
  287.                case MI_XYREGIONLOCK:
  288.                   Pict->XRegionLock=Pict->YRegionLock=TRUE;
  289.                   AttrOnOff(Pict, MI_XREGIONLOCK);
  290.                   AttrOnOff(Pict, MI_YREGIONLOCK);
  291.                   break;
  292.                case MI_YREGIONLOCK:
  293.                   Pict->YRegionLock=!Pict->YRegionLock;
  294.                   AttrOnOff(Pict, MI_YREGIONLOCK);
  295.                   break;
  296.                case MI_XREGIONLOCK:
  297.                   Pict->XRegionLock=!Pict->XRegionLock;
  298.                   AttrOnOff(Pict, MI_XREGIONLOCK);
  299.                   break;
  300.                default: break;
  301.                }
  302.                break;
  303.  
  304.             default: break;
  305.  
  306.             } /* switch */
  307.          } /* if ((class == MENUPICK) ...*/
  308.          else if (class == MOUSEBUTTONS) {
  309.                switch (code) {
  310.                case SELECTUP: break;
  311.                case SELECTDOWN:
  312.                   if (RubberObj && !RubberBand) { /* BEGIN RUBBERBAND */
  313.                      RubberBand = TRUE; x0 = x1 = x; y0 = y1 = y;
  314.                      SetDrMd(rp,COMPLEMENT); window->Flags |= RMBTRAP;
  315.                      if (RubberObj == BOX || RubberObj == REGION)
  316.                         RubberBox(x0,y0,x,y);
  317.                   }
  318.                   else { /* END RUBBERBAND */
  319.                      RubberBand = FALSE;
  320.                      if (RubberObj == BOX || RubberObj == REGION) {
  321.                         RubberBox(x0,y0,x1,y1);
  322.                         if (RubberObj == REGION) {
  323.                            PToU(Pict,min(x0,x),MAXVERT-max(y0,y),&XMin,&YMin);
  324.                            PToU(Pict,max(x0,x),MAXVERT-min(y0,y),&XMax,&YMax);
  325.                            Reg = Pict->CurrReg;
  326.                            if (!Pict->XRegionLock)
  327.                               {Reg->XMin = XMin; Reg->XMax = XMax;}
  328.                            if (!Pict->YRegionLock)
  329.                               {Reg->YMin = YMin; Reg->YMax = YMax;}
  330.                            retval = REPLOT;
  331.                         }
  332.                      }
  333.                      if (!XHair) SetDrMd(rp,JAM1);
  334.                      window->Flags &= 0xFFFFFFFF ^ RMBTRAP;
  335.                      RubberObj = NO_OBJECT;
  336.                      /* Draw object if applicable */
  337.                   }
  338.                   break;
  339.                case MENUDOWN: /* ABORT RUBBERBAND */
  340.                   RubberBand = FALSE; window->Flags &= 0xFFFFFFFF ^ RMBTRAP;
  341.                   if (RubberObj == BOX || RubberObj == REGION)
  342.                      RubberBox(x0,y0,x1,y1);
  343.                   break;
  344.                default: break;
  345.             } /* switch (code) */
  346.             break;
  347.          } /* else if (class == MENUBUTTONS) */
  348.       } /* while */
  349.       
  350.       if (MouseMoved && ((x1!=x) || (y1!=y)) ) {
  351.          if (XHair)
  352.                {PutXHair(x1,y1); PutXHair(x,y);}
  353.          if (RubberBand) {
  354.             if (RubberObj == BOX || RubberObj == REGION)
  355.                {RubberBox(x0,y0,x1,y1); RubberBox(x0,y0,x,y);}
  356.          }
  357.          x1 = x; y1 = y;
  358.       }
  359.    } while(retval == NOACTION);
  360.  
  361.    CleanUp();
  362.    return(retval);
  363. }
  364.